package com.yonyou.cyxdms.basedata.service.controller.brand;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyx.function.utils.common.StringUtils;
import com.yonyou.cyxdms.basedata.service.service.brand.BrandService;
import com.yonyou.cyxdms.basedata.service.vo.CarbrandInfoVO;
import com.yonyou.cyxdms.basedata.service.vo.IntentCarCMSVO;
import com.yonyou.cyxdms.basedata.service.vo.IntentCarVo;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author guorenpeng
 * @since 2018-09-10
 */
@RestController
@RequestMapping("/api/brand/carbrand")
@Api(tags = {"品牌相关接口"})
public class CarbrandController extends BaseController {
    public final Logger logger = LoggerFactory.getLogger(CarbrandController.class);

    @Autowired
    public BrandService brandPoService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author guorenpeng
     * @since 2018-09-10
     */
    @ResponseBody
    @GetMapping("/")
    @SuppressWarnings("unchecked")
    public IPage<Map<String, Object>> getList(@RequestParam Map<String, Object> queryCondition) {
        Page<Map<String, Object>> page = new Page(1, 2);
        return brandPoService.selectPageBysql(page, queryCondition);
    }

    /**
     * 查询list
     *
     * @param queryCondition 查询条件
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author guorp1
     * @since 2018/9/26
     */
    @ResponseBody
    @GetMapping("/selectListBySql")
    public List<Map<String, Object>> selectListBySql(@RequestParam Map<String, Object> queryCondition) {
        return brandPoService.selectListBySql(queryCondition);
    }

    /**
     * //根据经销商id获取经销商品牌列表
     *
     * @author dengqiang
     * @since 2019/1/7
     */
    @GetMapping("/carbrandList")
    @ApiOperation(notes = "品牌列表", value = "品牌列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dealerId", required = true, dataType = "Long", paramType = "header", value =
                    "经销商id"),
    })
    public List<CarbrandInfoVO> queryCarbrandInfo(@RequestHeader("appId") String appId) {
        logger.debug("开始");
        appId = StringUtils.isBlank(appId)
                ? ApplicationContextHelper.getBeanByType(LoginInfoDto.class).getAppId() : appId;
        return brandPoService.queryCarbrandInfo(appId);
    }

    /**
     * 根据id查找
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/10/17
     */
    @GetMapping("/queryBrandRelatedData")
    public Map<String, Object> queryBrandRelatedData(
            @ApiParam("品牌ID") @RequestParam(value = "brandId",
                    required = false) Long brandId,
            @ApiParam("车型ID") @RequestParam(value = "modelId",
                    required = false) Long modelId,
            @ApiParam("车系ID") @RequestParam(value = "seriesId",
                    required = false) Long seriesId,
            @ApiParam("配置ID") @RequestParam(value = "packageId",
                    required = false) Long packageId,
            @ApiParam("选装ID") @RequestParam(value = "optionId",
                    required = false) Long optionId) {
        //品牌

        return this.brandPoService.queryBrandRelatedData(brandId, modelId, seriesId, packageId, optionId);
    }

    /**
     * 根据code获取基础数据
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/11/15
     */
    @GetMapping("/queryBrandRelatedDataByCode")
    public Map<String, Object> queryBrandRelatedDataByCode(
            @ApiParam("品牌Code") @RequestParam(value = "brandCode",
                    required = false) String brandCode,
            @ApiParam("车型Code") @RequestParam(value = "modelCode",
                    required = false) String modelCode,
            @ApiParam("车系Code") @RequestParam(value = "seriesCode",
                    required = false) String seriesCode,
            @ApiParam("配置Code") @RequestParam(value = "packageCode",
                    required = false) String packageCode,
            @ApiParam("选装Code") @RequestParam(value = "optionCode",
		            required = false) String optionCode,
            @ApiParam("appId") @RequestParam(value = "appId") String appId) {
        //品牌

        return this.brandPoService.queryBrandRelatedDataByCode(brandCode, modelCode, seriesCode, packageCode, optionCode, appId);
    }

    /**
     * 批量获取车型类数据
     *
     * @param:
     * @return: map<目标数据标识, param>
     * @auther: tanjie
     * @since: 2019/11/15
     */
    @PostMapping("/queryBrandRelatedAll")
    public Map<Long, IntentCarVo> queryBrandRelatedAll(@RequestBody Map<Long, IntentCarVo> paramArr) {
        return this.brandPoService.queryBrandRelatedAll(paramArr);
    }


    /**
     * 批量获取车型类数据
     *
     * @param:
     * @return: map<目标数据标识, param>
     * @auther: tanjie
     * @since: 2019/11/15
     */
    @PostMapping("/queryBrandRelatedAllCMS")
    public Map<Long, IntentCarCMSVO> queryBrandRelatedAllCms(@RequestBody Map<Long, IntentCarCMSVO> paramArr) {
        return this.brandPoService.queryBrandRelatedAllCms(paramArr);
    }

	@PostMapping("/queryBrandRelatedAllCMSOptimization")
	public Map<String, IntentCarCMSVO> queryBrandRelatedAllCmsOptimization(@RequestBody Map<String, IntentCarCMSVO> paramArr) {
		return this.brandPoService.queryBrandRelatedAllCmsOptimization(paramArr);
	}




    /**
     * 通过车型或者配置ID获取上级ID
     *
     * @param:
     * @return: map<目标数据标识, param>
     * @auther: tanjie
     * @since: 2019/11/20
     */
    @PostMapping("/queryUpIntentCar")
    public IntentCarVo queryUpIntentCar(@RequestBody IntentCarVo intentCarVo) {
        return this.brandPoService.queryUpIntentCar(intentCarVo);
    }
}